//
//  YFTextAttachment.swift
//  Emoji
//
//  Created by 余仿 on 16/4/20.
//  Copyright © 2016年 yf. All rights reserved.
//

import UIKit

class YFTextAttachment: NSTextAttachment {

    var chs:String?


    //表情图片转属性文本
    class func emotionImage2AttributeString(emoji:YFEmoji,textFont font:UIFont) -> NSAttributedString{

        //点击了图片
        let image = UIImage(named: emoji.imagePath ?? "xxx")

        //将根据图片创建文本附件
        let attach = YFTextAttachment()

        attach.image = image

        attach.chs = emoji.chs

        //获取行高
        let lineHeight = font.lineHeight

        attach.bounds = CGRect(x: 0, y: -4, width: lineHeight, height:lineHeight)

        //根据文本附件创建属性字符串
        let attachStr = NSAttributedString(attachment: attach)
        
        return attachStr
    }
}
